<form id="power_form">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h4 class="modal-title">权限设置</h4>
	</div>
	<div class="modal-body">
		<input type="hidden" name="group" value="<?php echo $group_id;?>" >
		<table class="table" id="module_table">
			<thead>
				<tr>
					<th><input type="checkbox" id="checkall"/>父模块</th>
					<th>子模块</th>
					<th>操作权限</th>
					<th>操作URL</th>
				</tr>
			</thead>
		<tbody>
		<?php foreach ($modules as $father):?>
		<tr class="active">
			<td><input type="checkbox" id="module_<?php echo $father['module_id'];?>" class="module" name="module[]" value="<?php echo $father['module_id'];?>" <?php check_in_array($g_modules,'module_id',$father['module_id']);?>/><?php echo $father['module_name'];?></td>									
			<td></td>
			<td></td>
			<td></td>
		</tr>
		<?php if(isset($father['childrens'])&&is_array($father['childrens'])&&count($father['childrens'])):?>
			<?php foreach($father['childrens'] as $children):?>
				<tr>
					<td></td>
					<td><input type="checkbox" class="module_child module_<?php echo $father['module_id'];?>" id="module_child_<?php echo $children['module_id'];?>" value="<?php echo $children['module_id'];?>" name="module[]" <?php check_in_array($g_modules,'module_id',$children['module_id']);?>/><?php echo $children['module_name'];?></td>																		
					<td></td>
					<td><?php echo $children['module_url'];?></td>
				</tr>
				<?php if(isset($children['actions'])&&is_array($children['actions'])&&count($children['actions'])>0):?>
					<?php foreach($children['actions'] as $action):?>
						<tr>
							<td></td>
							<td></td>
							<td><input type="checkbox" class="action module_<?php echo $father['module_id'];?> module_child_<?php echo $children['module_id'];?>" value="<?php echo $action['action_id'];?>" name="action[]" <?php check_in_array($g_actions,'action_id',$action['action_id']);?>/><?php echo $action['action_name'];?></td>
							<td><?php echo $action['action_url'];?></td>
						</tr>
					<?php endforeach;?>
				<?php endif;?>
			<?php endforeach;?>
		<?php endif;?>
	<?php endforeach;?>
	</tbody>
	</table>																
		</div>
		<div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			<button type="submit" class="btn btn-primary">保存设置</button>
		</div>
	</form>

<script>
	$(document).ready(function() {

		function showResponse (responseText, statusText) { 
			if(responseText.code==0) {
				toastr.success("更新成功");
				$('#power-modal').hide();
			} else {
				toastr.error(responseText.msg);
			}
		}

    	var options = {
    		type:"post",
	        url:"user/group_permission_update",
	        dataType:'json',
			success:showResponse, 
    	}

    	$('#power_form').submit(function() { 
			$('#power_form').ajaxSubmit(options);
			return false;	
		});		
	});
</script>